open Octi_rawb

let b  = Bytes.create (8*4)
let b0 = Bytes.make_offset b 0
let b1 = Bytes.make_offset b 1
let b3 = Bytes.make_offset b1 2
let b0b = Bytes.make_offset b1 (-1)

let _ = (
  Bytes.get_size b,
  Bytes.get_size b0,
  Bytes.get_size b1,
  Bytes.get_size b3)

let _ = (
  Bytes.get_bbrefcount b,
  Bytes.get_bbrefcount b0,
  Bytes.get_bbrefcount b1,
  Bytes.get_bbrefcount b3)

let _ = (
  Bytes.get_offset b,
  Bytes.get_offset b0,
  Bytes.get_offset b1,
  Bytes.get_offset b3)

let _ = (
  Bytes.get_bbaddress b,
  Bytes.get_bbaddress b0,
  Bytes.get_bbaddress b1,
  Bytes.get_bbaddress b3)

let b8 = Bytes.make_offset b0 8
let _ = Bytes.C.Float64.set b0 1 3.14
let _ = Bytes.C.Float64.set b0 2 6.28
let _ = Bytes.C.Float64.get b8 0
let _ = Bytes.C.Float64.get b8 1

let _ = Bytes.C.Float64.set b 2 0.0
let _ = Bytes.C.Float64.set b 3 1.0
let _ = Bytes.C.ComplexFloat64.get b 1

let pv v =
  print_string "vector\n";
  List.iter (fun x -> print_string (" " ^ (string_of_float x) ^ "\n")) (Vector.Float64.to_list v)

let v = Vector.Float64.create 0 2

let _ = Vector.Float64.fill_linspace v 10.0 12.0
let _ = Vector.Float64.set v 1 21.0

let vv = Vector.Float64.make_linspace 0 10 100.0 110.0

let _ = pv vv
let _ = pv v

let v = Vector.Float64.make_linspace 10 19 0.0 9.0
let sv1 = Vector.make_subvector v 10 0 4
let sv2 = Vector.make_subvector v 14 1 5

let _ = pv v
let _ = pv sv1
let _ = pv sv2

let _ = Vector.Float64.to_list v

let _ = Vector.Float64.mset v [(11,111.0);(12,112.112);(11,111.111)]
let _ = Vector.Float64.to_list v


let print_refcount b =
  print_string ("refcount = " ^ (string_of_int (Bytes.get_bbrefcount b)) ^ "\n")


let make_offset_and_printrefcount b =
  let b1 = Bytes.make_offset b 4
  in
    print_refcount b1
    
let test_refcount _ =
  let b0 = Bytes.create 12
  in 
    print_refcount b0;
    print_string "making an offset\n";
    make_offset_and_printrefcount b0;
    print_string "calling GC\n";
    Gc.full_major ();
    print_refcount b0

let _ = test_refcount ()
